﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using TpExtensions;


namespace TpBaseObjects.Base {
    public class InvoiceNumberRow {

        #region Members

        private Range myRow;

        #endregion

        #region Contructor

        public InvoiceNumberRow(Range row) {
            myRow = row;
        }

        #endregion

        #region Properties

        public string DebitorenKonto {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "A"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "A"];
                r1.Value = value;
            }
        }

        public bool IsFree {
            get {
                bool ret = false;
                Range r1 = myRow.Cells[1, "L"];
                if (r1.Value == null) {
                    if (bool.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public bool IsSummenZeile {
            get {
                bool ret = false;
                Range r1 = myRow.Cells[1, "L"];
                if (r1.Value != null) {
                    string t1 = Convert.ToString(r1.Value);
                    if (t1.Contains("Summe")) {
                        ret = true;
                    }
                }
                return ret;
            }
        }

        public int Monat {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "M"];
                if (r1.Value != null) {
                    if (int.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }

        }

        public string Kunde {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "N"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "N"];
                r1.Value = value;
            }
        }

        public string Projekt {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "O"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "O"];
                r1.Value = value;
            }
        }

        public DateTime RechnungsDatum {
            get {
                DateTime ret = new DateTime(1900, 1, 1);
                Range r1 = myRow.Cells[1, "L"];
                if (r1.Value != null) {
                    if (DateTime.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "L"];
                r1.Value = value;
            }
        }

        public string Rechnungsempfänger {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "P"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "P"];
                r1.Value = value;
            }
        }

        public int RechnungsNummer {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "M"];
                if (r1.Value != null) {
                    if (int.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "M"];
                r1.Value = value;
            }
        }

        public string SachKonto {
            get {
                string ret = "";
                Range r1 = myRow.Cells[1, "B"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "B"];
                r1.Value = value;
            }
        }

        public double SummeNetto {
            get {
                double ret = 0;
                Range r1 = myRow.Cells[1, "Q"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "Q"];
                r1.Value = value;
            }
        }

        public double Ust {
            get {
                double ret = 0;
                Range r1 = myRow.Cells[1, "R"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "R"];
                r1.Value = value;
                r1.Font.ColorIndex = XlColorIndex.xlColorIndexAutomatic;
            }
        }

        public double VjProzent {
            get {
                double ret = 0;
                Range r1 = myRow.Cells[1, "U"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
            set {
                Range r1 = myRow.Cells[1, "U"];
                r1.Value = value;
            }
        }

        public int ZeilenNummer {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "A"];
                if (r1.Value != null) {
                    if (int.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        #endregion

        #region Methods

        public void ResetRow() {
            Range r1;
            r1 = myRow.Cells[1, "A"];
            r1.Value = "";
            r1 = myRow.Cells[1, "B"];
            r1.Value = "";
            r1 = myRow.Cells[1, "L"];
            r1.Value = "";
            r1 = myRow.Cells[1, "M"];
            r1.Value = "";
            r1 = myRow.Cells[1, "N"];
            r1.Value = "";
            r1 = myRow.Cells[1, "O"];
            r1.Value = "";
            r1 = myRow.Cells[1, "P"];
            r1.Value = "";
            r1 = myRow.Cells[1, "Q"];
            r1.Value = "";
            r1 = myRow.Cells[1, "R"];
            r1.Value = "";
            r1 = myRow.Cells[1, "U"];
            r1.Value = "";
        }

        public void SetBold() {
            Range r1 = this.myRow;
            //r1.Font.Name = Extensions.tpFontBold;
            Extensions.SetFontBoldOrNormal(r1, Extensions.tpFont.Bold);
        }

        #endregion

    }
}
